package com.tourlaid.mamagerment.ao.wx.impl

import com.github.pagehelper.Page
import com.github.pagehelper.PageHelper
import com.tourlaid.mamagerment.ao.wx.MyTraceAo
import com.tourlaid.mamagerment.entity.ResponseData
import com.tourlaid.mamagerment.service.TraceService
import com.tourlaid.mamagerment.util.DateUtil
import com.tourlaid.mamagerment.util.LoginUtil
import org.springframework.stereotype.Service
import org.springframework.util.CollectionUtils
import java.util.*
import javax.annotation.Resource

/**
 * Created by xiaoyongge on 2017/8/31.
 */
@Service("myTraceAo")
class MyTraceAoImpl : MyTraceAo {

    @Resource
    val traceService : TraceService?= null

    override fun queryData(pageNo: Int): ResponseData<MutableList<MutableMap<String, Any?>>> {
        var mutableList: MutableList<MutableMap<String, Any?>> = mutableListOf()
        var responseData = ResponseData(mutableList)
        PageHelper.startPage<Map<String, Any?>>(pageNo, 10, true)
        val page=  traceService!!.queryTraceMap(LoginUtil.userId!!) as Page<Map<String, Any?>>
        responseData.totalCount = page.getTotal()
        var resultList = page.getResult()
        if(CollectionUtils.isEmpty(resultList)){
            return responseData
        }
        for(map in resultList){
            val date = DateUtil.getFormantDate(map.get("create_time") as Date, DateUtil.DATA_FORMANT3)
            var mutableMap = mutableMapOf(
                    "storeId" to  map.get("store_id") as Long,
                    "image" to  map.get("image") as String,
                    "date" to date,
                    "storeName" to map.get("store_name") as String)
            mutableList.add(mutableMap)
        }
        return responseData
    }

}